define(function(require, exports, module) {
	'use strict';
    
    var rk = require('rk');
    require('core/rk.jq');

    var rk_userService = require('core/services/2.0/rk_userService');

    (function () {
        var templateMap ={
            workreport:{
                'template_statistics-1':(require('oa/tmpl/workreport/asset/template_statistics-1.tpl')),
                'template_statistics-2':(require('oa/tmpl/workreport/asset/template_statistics-2.tpl')),
                'template_statistics-3':(require('oa/tmpl/workreport/asset/template_statistics-3.tpl')),
                'template_statistics-4':(require('oa/tmpl/workreport/asset/template_statistics-4.tpl')),
                'template_statistics-5':(require('oa/tmpl/workreport/asset/template_statistics-5.tpl')),
                'template_statistics-6':(require('oa/tmpl/workreport/asset/template_statistics-6.tpl')),
                'template_statistics-7':(require('oa/tmpl/workreport/asset/template_statistics-7.tpl')),
                'template_statistics-8':(require('oa/tmpl/workreport/asset/template_statistics-8.tpl')),
                'template_statistics-13':(require('oa/tmpl/workreport/asset/template_statistics-13.tpl')),
                'template_statistics-14':(require('oa/tmpl/workreport/asset/template_statistics-14.tpl')),
                'template_statistics-15':(require('oa/tmpl/workreport/asset/template_statistics-15.tpl')),
                'template_statistics_Customized':(require('oa/tmpl/workreport/asset/template_statistics_Customized.tpl'))
            }
        };

        $.widget('rk.wrStatisticsPopupCtrl', {
            _create: function () {
                var me = this;
                var elem = me.element;
            },
            _init: function () {
                var me = this;
                var elem = me.element;
                var bizNum = me.options.bizNum;
                var ctrlNum = Math.abs(bizNum);
                var data = me.options.data;
                var winId = me.options.winId;

                var typeAlias = me.options.typeAlias;
                var ownerInfo = rk_userService.getUserInfo(me.options.ownerId);
                data.dateTitle = workreportService.getDateTitle(me.options.start, typeAlias, 'cn');
                data.bizText = me.options.bizText;

                data.ownerName = ownerInfo.name;
                data.ownerId = me.options.ownerId;

                data = me._handleData(data);
                data.ctrlNum = ctrlNum;
                data.ctxUrl = '';

                var templateId = me.options.templateId;//有些类型的弹出会指定模板，比如-10任务
                if (!templateId) {
                    if (parseInt(bizNum) > 0) {
                        templateId = 'template_statistics_Customized';
                    } else {
                        templateId = 'template_statistics' + bizNum;
                    }
                }

                var re = templateMap.workreport[templateId];
                var html =  rk.templateText(re,data);

                //var html = template(templateId, data);
                var win = $('#' + winId);
                win.html(html);
                if (me._afterPopup) {
                    me._afterPopup(winId);
                }
                win.find('.pop_content').beScroll();
                if ($.browser.msie && $.browser.version < 9) {
                    var _oh = win.outerHeight();
                    if (_oh > 500) {
                        win.css('top', '100px');
                    }
                } else {
                    $(window).trigger('resize');//触发resize，popup可以重新定位一下，内容超高时有用
                }                
            },
            handleClose: function () {
                var me = this;

                $(window.document).off('mousewheel.zl');
                window.setTimeout(function(){
                    $(window).trigger('resize');
                }, 100);
            }
        });
    })();

});